<template>
  <el-table :data="orderModel.getList()" style="width: 100%;" @row-click="row => $emit('info', row)">
    <el-table-column :label="plugin.lang('order.code')" width="300">
      <template #default="scope">
        {{ scope.row.code }}
      </template>
    </el-table-column>
    <el-table-column :label="plugin.lang('order.type')">
      <template #default="scope">
        <el-tag 
          :type="scope.row.type == 'ticket' ? 'warning' : (scope.row.type == 'print' ? '' : 'danger')" 
          effect="plain"
        >
          {{ plugin.lang('order.type_text.' + scope.row.type) }}
        </el-tag>
      </template>
    </el-table-column>
    <el-table-column :label="plugin.lang('order.client_name')" prop="client_name">
      <template #default="scope">
        {{ scope.row.order.client_name }}
      </template>
    </el-table-column>
    <el-table-column :label="plugin.lang('order.discount_money')" prop="discount_money" align="center">
      <template #default="scope">
        {{ money(scope.row.order.discount_money) }}
      </template>
    </el-table-column>
    <el-table-column :label="plugin.lang('order.money_tax')" prop="money_tax" align="center">
      <template #default="scope">
        {{ money(scope.row.order.money_tax) }}
      </template>
    </el-table-column>
    <el-table-column :label="plugin.lang('order.money')" prop="money" align="center">
      <template #default="scope">
        <el-link type="primary" href="javascript:;">{{ money(scope.row.order.money) }}</el-link>
      </template>
    </el-table-column>
    <el-table-column :label="plugin.lang('order.time')" width="150">
      <template #default="scope">
        {{ time.format(scope.row.order.created_at) }}
      </template>
    </el-table-column>
    <el-table-column fixed="right" align="right">
      <template #default="scope">
        <el-button type="primary" size="small" style="margin-left: 10px" @click="$emit('upload', scope.row)"><i class="iconfont mini icon-upload-max el-icon--right"></i> {{ plugin.lang('order.upload') }}</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import app from '@/app'
import orderModel from '../../model/order'

export default {
  setup() {
    orderModel.get()

    return {
      lang: app.lang,
      plugin: app.plugin.index,
      time: app.time,
      money: app.money,
      orderModel,
    }
  }
}
</script>